﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

namespace CoNatural.Data.VisualStudio.AddIn.Forms {
	public partial class DesignCommandWizardForm : WizardForm {
		private ProjectItem item;

		private Controls.SelectConnectionControl step0;
		private Controls.CommandPreviewControl step1;

		public DesignCommandWizardForm(string name, ProjectItem item) {
			InitializeComponent();

			this.item = item;
			this.Text = "CoNatural Command Design Wizard - " + name;

			step0 = new CoNatural.Data.VisualStudio.AddIn.Controls.SelectConnectionControl();
			step1 = new CoNatural.Data.VisualStudio.AddIn.Controls.CommandPreviewControl();

			Initialize(
				new WizardStep(step0, false, false, "Step 1 of 2 - Select the data source.", new[] { "1) Select the connection string to the data source." }),
				new WizardStep(step1, true, true, "Step 2 of 2 - Preview Command.", new[] { "1) Enter input parameter values.", "2) Excute command and preview results." })
			);
		}

		protected override bool OnGoBack() {
			return base.OnGoBack();
		}

		protected override bool OnGoNext() {
			if (CurrentStepIndex == 0) {
				string connectionString = step0.GetSelectedConnectionString();
				if (!string.IsNullOrEmpty(connectionString)) {
					step1.Initialize(connectionString, item);
					return true;
				}
			}
			return false;
		}

		protected override bool OnFinish(BackgroundWorker worker) {
			// TODO
			return true;
		}
	}
}
